public class TestDemo {
    public static void main(String[] args) {
        int[] array = new int[100];
        func2(array);
        for (int x:array) {
            System.out.print(x + " ");
        }
        System.out.println();
    }
    public static void func2(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i + 1;
        }
    }
    /**
     * 实现一个方法 printArray, 以数组为参数, 循环访问数组中的每个元素, 打印每个元素的值.
     * @param args
     */
    public static void main4(String[] args) {
        int[] array = {1,2,3,3,4,5,6,7,8,9,10};
        printArray(array);
    }
    public static void printArray(int[] array) {
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();
    }
    /**
     * 实现一个方法 transform, 以数组为参数, 循环将数组中的每个元素 乘以 2 , 并设置到对应的数组元素上. 例如 原数组为 {1, 2, 3}, 修改之后为 {2, 4, 6}
     * @param args
     */
    public static void main3(String[] args) {
        int[] array = {1,2,3,3,4,5,6,7,8,9,10};
        System.out.println("改变之前");
        for (int x: array) {
            System.out.print(x+" ");
        }
        System.out.println();
        func1(array);
        System.out.println("改变之后");
        for (int x: array) {
            System.out.print(x + " ");
        }
        System.out.println();
    }
    public static void func1(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] *= 2;
        }
    }
    public static void main2(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        int ret = sum(array);
        System.out.println(ret);
    }
    public static int sum(int [] array) {
        int sum = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        return sum;
    }
    /**
     * 实现一个方法 avg, 以数组为参数, 求数组中所有元素的平均值(注意方法的返回值类型).
     * @param args
     */
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9,10};
        double ret = avg(array);
        System.out.println(ret);
    }
    public static double avg(int[] array) {
        int sum = 0;
        double avg = 0;
        for (int i = 0; i < array.length; i++) {
            sum += array[i];
        }
        avg = (double) sum/ array.length;
        return avg;
    }
}
